package dao;
import java.util.List;

import org.hibernate.classic.Session;
import org.hibernate.Transaction;

import util.HibernateUtil;
import entity.Marca;
import entity.OrdemServico;

public class OrdemServicoDaoImplementation implements OrdemServicoDao {

	public void save(OrdemServico ordemServico) 
	{
		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction transaction = session.beginTransaction();
		session.save(ordemServico);
		transaction.commit();
		session.close();
	}

	public void update(OrdemServico ordemServico) 
	{
		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction transaction = session.beginTransaction();
		session.update(ordemServico);
		transaction.commit();
		session.close();
	}

	public void delete(OrdemServico ordemServico) 
	{
		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction transaction = session.beginTransaction();
		session.delete(ordemServico);
		transaction.commit();
		session.close();
	}

	public void consult(OrdemServico ordemServico) 
	{
		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction transaction = session.beginTransaction();
		ordemServico = (OrdemServico) session.load(OrdemServico.class, new String("OrdemServico"));
	}

	public OrdemServico getOrdemServico(long id) 
	{
		Session session = HibernateUtil.getSessionFactory().openSession();
		return (OrdemServico) session.load(OrdemServico.class, id);
	}
	
	public List<OrdemServico> list() 
	{
	Session session = HibernateUtil.getSessionFactory().openSession();
	Transaction transaction = session.beginTransaction();
	String sql = "SELECT new OrdemServico( o.idOrdemServico, o.cliente, o.dataEmissao, o.dataChegada, o.condicaoPagamento) FROM OrdemServico o";
	List<OrdemServico> lista = session.createQuery(sql).list();
	transaction.commit();
	session.close();
	return lista;
	}
	
	

}
